﻿
using IOP.ISEA;
using IOP.ISEA.OBJ;
using IOP.SgrA;
using IOP.SgrA.SilkNet.Vulkan;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace VkSample71
{
    class Program
    {
        static async Task Main(string[] args)
        {
            await CreateISEA(true);
            var h = Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((config) =>
                {
                    config.SetBasePath(Directory.GetCurrentDirectory());
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) config.AddVulkanJsonFile("Vulkan.json");
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) config.AddVulkanJsonFile("Vulkan-Linux.json");
                    else throw new NotSupportedException("Not supported Platform");
                })
                .ConfigureSgrAHost((sgra) =>
                {
                    sgra.AddVulkanEnvironmental();
                    sgra.UseStartup<Startup>();
                }).ConfigureLogging((logger) => logger.AddConsole()); ;
            await h.RunConsoleAsync();
        }

        static async Task CreateISEA(bool isNeed)
        {
            if (!isNeed) return;
            var basePath = AppContext.BaseDirectory;
            var modelsPath = Path.Combine(basePath, "Assets", "Models");
            OBJDocument obj = await OBJDocument.LoadAsync(Path.Combine(modelsPath, "ch.obj"));
            ISEADocument isea = new ISEADocument();
            MeshNode[] nodes = isea.CreateMeshNodeFromOBJ(obj, 0, 0, new MeshDataPurpose[] { MeshDataPurpose.POSITION });
            isea.CreateRenderObjectNode("CH", nodes[0]);
            await isea.Save(basePath, "test71");
            obj.Dispose();
        }
    }
}
